import todoHandler from "/handlers/todoHandler.js";
export async function newHandler(str, id, tdcontent) {
    const newNoteURL = '/notes/newNoteByUid';
    const newTodoURL = '/todos/newTodoByUid';
    let uid = Number(id);
    let res = await axios.get("/getDate");
    let dateStr = res.data;
    if (str === 'note') {
        axios.post(newNoteURL, {
            "uid": uid,
            "date": dateStr
        }
        ).then(res => {
            if (res.data.ok === 1) {
                Qmsg.success('新增笔记成功！');
                window.setTimeout(function () {
                    window.location.reload();
                }, 500)
            } else {
                Qmsg.error('新增笔记失败！');
            }
            console.log('新增的结果', res.data);
        }).catch(error => {
            alert(error);
        })
    } else if (str === 'todo') {
        axios.post(newTodoURL, {
            "uid": uid,
            "date": dateStr,
            "content": tdcontent
        }
        ).then(res => {
            if (res.data.ok === 1) {
                todoHandler.flashUpDone();
                Qmsg.success('新增待办成功！');
            } else {
                Qmsg.error('新增待办失败！');
            }
            console.log('新增的结果', res.data);
        }).catch(error => {
            alert(error);
        })
    }
}